import React, {Component} from 'react';

import {
    StyleSheet,
    Text,
    View,
    Platform,
    Dimensions,
    TouchableOpacity,
    Image,
    DeviceEventEmitter,
} from 'react-native';

import HttpUtils from '../../utils/HttpUtils';
import HttpUrls from '../../utils/HttpUrls';
import Header from '../../components/header';
import Loading from '../../utils/Loading';
import NoData from '../../utils/NoData';
import {getImgUrl} from '../../utils/ComFunction';
import AlertCommonView from "../../components/Tool/AlertCommonView";
import {ToastToUser} from "../../utils/CustomToast";
import Constant from "../../utils/Constant";
import SeekItemView from "./seekComponents/SeekItemView";

const isIos = Platform.OS == 'ios';
const screenW = Dimensions.get('window').width;
const screenH = Dimensions.get('window').height;

let navigation;

export default class SeekingInfoPage extends Component {
    constructor(props) {
        super(props);
        this.state = {
            seekingDetail: {},
        };
    }

    componentDidMount() {

        this.getData()
    }

    render() {
        navigation = this.props.navigation;
        return (
            <View style={styles.container}>
                <Header navigation={navigation} Title="求购详情" />

                {this.state.seekingDetail && Object.keys(this.state.seekingDetail).length > 0 ? (
                    <SeekItemView
                        item={this.state.seekingDetail}
                        buyerId={Constant.userInfo.buyerId}
                        navigation={navigation}
                        isDetail={true}
                    ></SeekItemView>
                ): null}

                <Loading onRef={ref => (this.Loading = ref)} />
            </View>
        );
    }

    getData() {
        let routeData = this.props.route.params;
        let param = {
            id: routeData.id ? routeData.id : null,
        };
        let carMatchCount = routeData.carMatchCount || 0;
        this.Loading.show();
        HttpUtils.getRequest(HttpUrls.getCarPurchaseDetail, param)
            .then(result => {
                console.log(result)
                if(result.code === 0){
                    // 添加列表传过来的匹配车辆数
                    result.data.carMatchCount = carMatchCount;
                    this.setState({
                        seekingDetail: result.data
                    })
                }
            })
            .catch(error => {
                console.log(error);
            })
            .finally(() => {
                this.Loading.hide();
            });
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: '#F9F9F9',
    },

});
